<?php
include '../setup.php';

$set = new setup();

$postfields = array($searchterm_fname,$searchterm_phone ,$searchterm_email);
$dbfields = array('user_fname','user_phone1','user_website');
$qryfields = array();
$i=0;

foreach ($postfields as $pf) {
    if($pf!=="") {
        array_push($qryfields,"$dbfields[$i]='".$pf."'");
    }
    $i++;
}

if($searchterm_fname=="" && $searchterm_phone=="" && $searchterm_email==""){

    $result = $set->qry("Select * from USERS WHERE user_level = 3");

}else{
    $result = $set->qry("Select * from USERS where " . join(" AND ",$qryfields)."AND user_level = 3");

}

?>
<div id = "results">

    <table>
        <th>Company Name</th><th>Location</th><th>Company Phone</th><th>Website</th><th>Tools</th>
        <th>
            <a href=<?php echo "companies.php?id=".$user_id."&action=new"?>><img src="imgs/new_icon.png" alt="new" title="new" width="30px"></a>
        </th>
        <?php
        while($row = mysql_fetch_assoc($result))
        {
            $user_id = $row['user_id'];
            ?>
            <tr>
                <td><?php echo $row['user_fname'] ?></td>
                <td><?php echo $row['user_autocomplete'] ?></td>
                <td><?php echo $row['user_phone1'] . " - " . $row['user_phone2'] ?></td>
				<td><a href="http://<?php echo $row['user_website']?>"><?php echo  $row['user_website']?> </a></td>
                <td>
                    <form action="companies.php" method="get">
                        <a href=<?php echo "companies.php?id=".$user_id."&action=view"?>><img src="imgs/view-icon.png" alt="view" title="View" width="25px"></a>
                    </form>
                </td>
            </tr>
            <?php } ?>
    </table>
</div>